home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / RPGSOUND.S < prev    next >
Encoding:
Text File  |  1993-10-02  |  16.3 KB  |  465 lines

  1. ; note: when you use this is your program, at the LAST ds.l
  2. ;       place enough ds.l instrs to equal the size of YOUR
  3. ;       largest sample file! if you dont, you might overwrite
  4. ;       some other program in memory, because when this program
  5. ;       (in its original form) loaded, it loaded the sample file
  6. ;       data in memory just below this code..
  7.  
  8.  
  9. ;                DigiPlay
  10. ;                adapted by Jeff Bilger    Internet:jmb8302@cs.tamu.edu
  11. ;                Texas A&M University, September 31,1993 -- 3:37am
  12. ;
  13. ;                This program is a modification of a program
  14. ;                written by ( David Snow on 3/8/89 ). The original program
  15. ;                loaded up as a TSR program and stole etv_term($408)
  16. ;                so it played a digitized sample whenever a program
  17. ;                ended.
  18. ;
  19. ;                I have modified it to accept parameters from
  20. ;                the cli of a .TTP type program.
  21. ;                The format is:
  22. ;
  23. ;                X filename
  24. ;
  25. ;                Where X is a number from 0-5 which represents the
  26. ;                playback frequency.
  27. ;                Filename is the name of the sound file(of course!)
  28. ;
  29. ;                I wrote this to use in an upcomming game where I
  30. ;                execute this program with Pexec as a TSR and save its
  31. ;                basepage address. Whenever I want to play a sound
  32. ;                during the execution of my own program, all I have
  33. ;                to do is a strcpy command of the form  'X filename'
  34. ;                to the command line image, which is 128 bytes from the
  35. ;                start of the basepage address. Finally I do another
  36. ;                call to Pexec (a GO command) and give it the basepage
  37. ;                address of the TSR prg and it executes and plays the
  38. ;                sample file that I just put into its command line
  39. ;                image......easy!!
  40.  
  41.  
  42.  
  43. starting: move.l 4(a7),a0    ;      calculate program size
  44.           move.l #$100,d6
  45.           add.l 12(a0),d6
  46.           add.l 20(a0),d6
  47.           add.l 28(a0),d6
  48.  
  49.           clr.l -(a7)         ;     enter supervisor mode
  50.           move.w #$20,-(a7)
  51.           trap #1
  52.           addq.l #6,a7
  53.           move.l d0,d4         ;    save ssp
  54.  
  55.           ;NOTE, the format of the command line in a ttp program is
  56.           ;      [size]filename
  57.           ; ie:8filename   would be a correct form
  58.           ;
  59.           ;I will send command line parameters in the form
  60.           ;SSbFFFFF
  61.           ;where:
  62.           ;       F is the name of the sample ie (THUND)
  63.           ;       b is a blank space
  64.           ;       S is the sample rate ie (4,5,6,7 etc)
  65.  
  66.  
  67.           lea starting,a0          ; find command parameter in ttp
  68.           sub.l #128,a0
  69.           clr.l   d0
  70.         
  71.           tst.w   (a0)        ;reject null name(ie if size = 0)
  72.           beq     exit        ; if d0=0 then exit
  73.   
  74.           move.b (a0),d0        ; d0 holds the length of the sample name
  75.                                 ; (actually holds length of command line string)
  76.         
  77.  
  78.           move.b 1(a0),sample_rate ; save the sample rate
  79.  
  80.           adda.l #3,a0          ; add 3 to address of filename
  81.                                 ; cause 1st byte held the size,2nd byte holds the freq
  82.           move.l a0,filename    ;save the address to the filename
  83.                                 ; of the sample
  84.           subi.b  #2,d0       ;subtract places for freq, and blank
  85.           move.b  #0,0(a0,d0) ;zero terminate tail
  86.                               ;thats register indirect w/ index
  87.  
  88.  
  89.  
  90.  
  91.          lea sample_rate(PC),a1    ;  convert frequency index
  92.           move.b (a1),d0
  93.  
  94.            sub.b #48,d0
  95.           lsl.b #1,d0
  96.           move.b d0,(a1)
  97.  
  98.  
  99.           pea dta(PC)           ;   set DTA
  100.           move.w #$1A,-(a7)
  101.           trap #1
  102.           addq.l #6,a7
  103.  
  104.  
  105.  
  106.           move.w #0,-(a7)         ; get sample file length
  107.           move.l filename(PC),-(a7)
  108.           move.w #$4E,-(a7)
  109.           trap #1
  110.           add.l #8,a7
  111.  
  112.           tst d0
  113.           bne problem
  114.  
  115.           lea dta(PC),a6  ;         save sample file length
  116.           move.l 26(a6),d7
  117.           add.l d7,d6      ;        add file length to program size
  118.  
  119.           lea snd_buf,a0
  120.           lea pointers(PC),a6;      save buffer pointer
  121.           move.l a0,(a6)+
  122.           move.l a0,a5
  123.           add.l d7,a0         ;     calculate buffer end pointer
  124.           move.l a0,(a6)       ;    save buffer end pointer
  125.  
  126.           clr.w -(a7)           ;   open sample file
  127.           move.l filename(PC),-(a7)
  128.           move.w #$3D,-(a7)
  129.           trap #1
  130.           add.l #8,a7
  131.  
  132.           tst.l d0
  133.           bmi problem
  134.           move.w d0,d5           ;  save file handle
  135.  
  136.           move.l a5,-(a7)         ; pointer to sample buffer
  137.           move.l d7,-(a7)  ;        size of sample buffer
  138.           move.w d5,-(a7)   ;       file handle
  139.           move.w #$3F,-(a7)  ;      read sample file
  140.           trap #1
  141.           add.l #12,a7
  142.  
  143.           tst.l d0
  144.           bmi problem
  145.  
  146.           move.w d5,-(a7)     ;     close sample file
  147.           move.w #$3E,-(a7)
  148.           trap #1
  149.           addq.l #4,a7
  150.  
  151.        
  152. problem   ;   GET PARAMETERS/ENTER SUPERVISOR MODE TO ACCESS I/O REGISTERS
  153.  
  154. start     movem.l d0-d7/a0-a6,-(a7); save registers
  155.  
  156.           move.l #$FF8800,a0       ;set up sound chip registers
  157.  
  158.           move.b #0,(a0)
  159.           move.b #0,2(a0)
  160.  
  161.           move.b #1,(a0)
  162.           move.b #0,2(a0)
  163.  
  164.           move.b #2,(a0)
  165.           move.b #0,2(a0)
  166.  
  167.           move.b #3,(a0)
  168.           move.b #0,2(a0)
  169.  
  170.           move.b #4,(a0)
  171.           move.b #0,2(a0)
  172.  
  173.           move.b #5,(a0)
  174.           move.b #0,2(a0)
  175.  
  176.           move.b #7,(a0)
  177.           move.b #$ff,2(a0)
  178.  
  179.           move.b #8,(a0)
  180.           move.b #0,2(a0)
  181.  
  182.           move.b #9,(a0)
  183.           move.b #0,2(a0)
  184.  
  185.           move.b #10,(a0)
  186.           move.b #0,2(a0)
  187.  
  188.           lea int_vector(PC),a6  ;  get internal interrupt vector
  189.           lea snd_out(PC),a4      ; get pointer to sound table
  190.  
  191.           lea kbd_off(PC),a0       ;disable keyboard
  192.           bsr ikbdws
  193.  
  194.           move.w #5,-(a7)   ;       disable timer c interrupt
  195.           move.w #26,-(a7)
  196.           trap #14
  197.           addq.l #4,a7          
  198.  
  199.           lea pointers(PC),a1
  200.           move.l (a1)+,a3    ;      get pointer to sound buffer
  201.           move.l (a1),d6      ;     get end-of-buffer pointer
  202.  
  203.           lea frequency(PC),a0 ;    get timer parameters
  204.           lea sample_rate(PC),a1
  205.           clr.w d0
  206.           move.b (a1),d0
  207.           move.w 0(a0,d0.w),d5
  208.           clr.w d4                 
  209.           move.w d5,d4          ;   extract timer parameters from d5
  210.           andi.w #$FF,d5         ;  get timer control byte
  211.           lsr.w #8,d4             ; get timer data data
  212.           bsr xbtimer              ;start mfp timer
  213.  
  214.           bclr  #3,$FFFA17 ;       set automatic end-of-interrupt mode
  215.           move.w sr,-(a7)    ;      save status register
  216.           move.w #$2400,sr    ;     permit level 6 interrupts only
  217.  
  218. ; MAIN PLAYBACK LOOP - TEST FOR END OF SAMPLE BUFFER
  219.  
  220. test_end  cmp.l a3,d6       ;       end of buffer?
  221.           bhi test_end
  222.  
  223. ; STOP INTERRUPT GENERATION
  224.  
  225.           move.w #$2700,sr   ;      disable all interrupts
  226.           bset  #3,$FFFA17   ;     set software end-of-interrupt mode
  227.           clr.w d5             ;    stop mfp timer
  228.           bsr xbtimer
  229.  
  230.           move.w #5,-(a7)       ;   re-enable timer c interrupt
  231.           move.w #27,-(a7)
  232.           trap #14
  233.           addq.l #4,a7          
  234.  
  235.           lea kbd_on(PC),a0      ;  re-enable keyboard
  236.           bsr ikbdws
  237.  
  238. clear     btst  #0,$FFFC00       ; characters in keyboard buffer?
  239.           beq re_status
  240.           move.b $FFFC02,d7  ;      if go, clear buffer
  241.           bra clear
  242.  
  243. re_status move.w (a7)+,sr     ;     retrieve status register
  244.           movem.l (a7)+,d0-d7/a0-a6; restore registers
  245.  
  246.  
  247. exit:     move.w #0,-(a7)           ; terminate stay resident
  248.           move.l #$14820,-(sp)      ; save 84k bytes
  249.           move.w #$31,-(sp)
  250.           trap   #1
  251.  
  252.  
  253.  
  254. ; TURN KEYBOARD OFF/ON
  255.  
  256. ikbdws    move.l a0,-(a7)    ;      pointer to string
  257.           move.w #0,-(a7)     ;     1 parameter in string
  258.           move.w #25,-(a7)     ;    write string to keyboard processor
  259.           trap #14
  260.           addq.l #8,a7
  261.           rts
  262.  
  263. ; START/STOP MFP TIMER A
  264.  
  265. xbtimer   move.l a6,-(a7)  ;        interrupt vector
  266.           move.w d4,-(a7)   ;       timer a data
  267.           move.w d5,-(a7)    ;      timer a control
  268.           move.w #0,-(a7)     ;     timer a select
  269.           move.w #31,-(a7)     ;    start mfp timer
  270.           trap #14
  271.           add.l #12,a7
  272.           rts
  273.  
  274. ; INTERRUPT ROUTINE
  275.  
  276. int_vector clr.w d7       ;         clear table lookup index
  277.           move.b (a3)+,d7  ;        get byte from sample buffer
  278.           add.b #$80,d7     ;       convert to signed value
  279.           lsl.w #3,d7        ;      double longword offset
  280.           move.l 0(a4,d7.w),d0;     load sound to psg registers
  281.           move.l #$FF8800,a2   ;    sound chip pointer
  282.           movep.l d0,0(a2)         ;move data to
  283.                                  ;    sound chip volume registers
  284.           move.w 4(a4,d7.w),d0  
  285.            movep.w d0,0(a2)
  286.  
  287.  
  288.           rte
  289. filename  ds.l 1
  290. sample_rate ds.b 2
  291. save_ssp  ds.l 1
  292. pointers  ds.l 2
  293.  
  294.  
  295. dta       ds.b 44
  296. kbd_off   dc.b $13,0
  297. kbd_on    dc.b $11,0
  298. frequency dc.w $0506,$0505,$0405,$2901,$1f01,$0802
  299.  
  300. ;  INTERNAL SOUND LOOKUP TABLE
  301.  
  302. snd_out   dc.w    $80c,$90b,$a09,0,$80c,$90b,$a09,0
  303.           dc.w    $80d,$908,$a08,0,$80b,$90b,$a0b,0
  304.           dc.w    $80d,$909,$a05,0,$80c,$90b,$a08,0
  305.           dc.w    $80d,$909,$a02,0,$80d,$908,$a06,0
  306.           dc.w    $80c,$90b,$a07,0,$80d,$907,$a07,0
  307.           dc.w    $80c,$90b,$a06,0,$80c,$90a,$a09,0
  308.           dc.w    $80b,$90b,$a0a,0,$80c,$90b,$a02,0
  309.           dc.w    $80c,$90b,$a00,0,$80c,$90a,$a08,0
  310.  
  311.           dc.w    $80d,$906,$a04,0,$80d,$905,$a05,0
  312.           dc.w    $80d,$905,$a04,0,$80c,$909,$a09,0
  313.           dc.w    $80d,$904,$a03,0,$80b,$90b,$a09,0
  314.           dc.w    $80c,$90a,$a05,0,$80b,$90a,$a0a,0
  315.           dc.w    $80c,$909,$a08,0,$80b,$90b,$a08,0
  316.           dc.w    $80c,$90a,$a00,0,$80c,$90a,$a00,0
  317.           dc.w    $80c,$909,$a07,0,$80b,$90b,$a07,0
  318.           dc.w    $80c,$909,$a06,0,$80b,$90b,$a06,0
  319.  
  320.           dc.w    $80b,$90a,$a09,0,$80b,$90b,$a05,0
  321.           dc.w    $80a,$90a,$a0a,0,$80b,$90b,$a02,0
  322.           dc.w    $80b,$90a,$a08,0,$80c,$907,$a07,0
  323.           dc.w    $80c,$908,$a04,0,$80c,$907,$a06,0
  324.           dc.w    $80b,$909,$a09,0,$80c,$906,$a06,0
  325.           dc.w    $80a,$90a,$a09,0,$80c,$907,$a03,0
  326.           dc.w    $80b,$90a,$a05,0,$80b,$909,$a08,0
  327.           dc.w    $80b,$90a,$a03,0,$80a,$90a,$a08,0
  328.  
  329.           dc.w    $80b,$90a,$a00,0,$80b,$909,$a07,0
  330.           dc.w    $80b,$908,$a08,0,$80a,$90a,$a07,0
  331.           dc.w    $80a,$909,$a09,0,$80c,$901,$a01,0
  332.           dc.w    $80a,$90a,$a06,0,$80b,$908,$a07,0
  333.           dc.w    $80a,$90a,$a05,0,$80a,$909,$a08,0
  334.           dc.w    $80a,$90a,$a02,0,$80a,$90a,$a01,0
  335.           dc.w    $80a,$90a,$a00,0,$809,$909,$a09,0
  336.           dc.w    $80a,$908,$a08,0,$80b,$908,$a01,0
  337.  
  338.           dc.w    $80a,$909,$a06,0,$80b,$907,$a04,0
  339.           dc.w    $80a,$909,$a05,0,$809,$909,$a08,0
  340.           dc.w    $80a,$909,$a03,0,$80a,$908,$a06,0
  341.           dc.w    $80a,$909,$a00,0,$809,$909,$a07,0
  342.           dc.w    $809,$908,$a08,0,$80a,$908,$a04,0
  343.           dc.w    $809,$909,$a06,0,$80a,$908,$a01,0
  344.           dc.w    $809,$909,$a05,0,$809,$908,$a07,0
  345.           dc.w    $808,$908,$a08,0,$809,$909,$a02,0
  346.  
  347.           dc.w    $809,$908,$a06,0,$809,$909,$a00,0
  348.           dc.w    $809,$907,$a07,0,$808,$908,$a07,0
  349.           dc.w    $809,$907,$a06,0,$809,$908,$a02,0
  350.           dc.w    $808,$908,$a06,0,$809,$906,$a06,0
  351.           dc.w    $808,$907,$a07,0,$808,$908,$a04,0
  352.           dc.w    $808,$907,$a06,0,$808,$908,$a02,0
  353.           dc.w    $807,$907,$a07,0,$808,$906,$a06,0
  354.           dc.w    $808,$907,$a04,0,$807,$907,$a06,0
  355.  
  356.           dc.w    $808,$906,$a05,0,$808,$906,$a04,0
  357.           dc.w    $807,$906,$a06,0,$807,$907,$a04,0
  358.           dc.w    $808,$905,$a04,0,$806,$906,$a06,0
  359.           dc.w    $807,$906,$a04,0,$807,$905,$a05,0
  360.           dc.w    $806,$906,$a05,0,$806,$906,$a04,0
  361.           dc.w    $806,$905,$a05,0,$806,$906,$a02,0
  362.           dc.w    $806,$905,$a04,0,$805,$905,$a05,0
  363.           dc.w    $806,$905,$a02,0,$805,$905,$a04,0
  364.  
  365.           dc.w    $805,$904,$a04,0,$805,$905,$a02,0
  366.           dc.w    $804,$904,$a04,0,$804,$904,$a03,0
  367.           dc.w    $804,$904,$a02,0,$804,$903,$a03,0
  368.           dc.w    $803,$903,$a03,0,$803,$903,$a02,0
  369.           dc.w    $803,$902,$a02,0,$802,$902,$a02,0
  370.           dc.w    $802,$902,$a01,0,$801,$901,$a01,0
  371.           dc.w    $802,$901,$a00,0,$801,$901,$a00,0
  372.           dc.w    $801,$900,$a00,0,$800,$900,$a00,0
  373.  
  374.           dc.w    $80e,$90d,$a0c,0,$80f,$903,$a00,0
  375.           dc.w    $80f,$903,$a00,0,$80f,$903,$a00,0
  376.           dc.w    $80f,$903,$a00,0,$80f,$903,$a00,0
  377.           dc.w    $80f,$903,$a00,0,$80e,$90d,$a0b,0
  378.           dc.w    $80e,$90d,$a0b,0,$80e,$90d,$a0b,0
  379.           dc.w    $80e,$90d,$a0b,0,$80e,$90d,$a0b,0
  380.           dc.w    $80e,$90d,$a0b,0,$80e,$90d,$a0b,0
  381.           dc.w    $80e,$90d,$a0a,0,$80e,$90d,$a0a,0
  382.  
  383.           dc.w    $80e,$90d,$a0a,0,$80e,$90d,$a0a,0
  384.           dc.w    $80e,$90c,$a0c,0,$80e,$90d,$a00,0
  385.           dc.w    $80d,$90d,$a0d,0,$80d,$90d,$a0d,0
  386.           dc.w    $80d,$90d,$a0d,0,$80d,$90d,$a0d,0
  387.           dc.w    $80d,$90d,$a0d,0,$80d,$90d,$a0d,0
  388.           dc.w    $80e,$90c,$a0b,0,$80e,$90c,$a0b,0
  389.           dc.w    $80e,$90c,$a0b,0,$80e,$90c,$a0b,0
  390.           dc.w    $80e,$90c,$a0b,0,$80e,$90c,$a0b,0
  391.  
  392.           dc.w    $80e,$90c,$a0b,0,$80e,$90c,$a0b,0
  393.           dc.w    $80e,$90c,$a0a,0,$80e,$90c,$a0a,0
  394.           dc.w    $80e,$90c,$a0a,0,$80e,$90c,$a0a,0
  395.           dc.w    $80d,$90d,$a0c,0,$80d,$90d,$a0c,0
  396.           dc.w    $80e,$90c,$a09,0,$80e,$90c,$a09,0
  397.           dc.w    $80e,$90c,$a05,0,$80e,$90c,$a00,0
  398.           dc.w    $80e,$90c,$a00,0,$80e,$90b,$a0b,0
  399.           dc.w    $80e,$90b,$a0b,0,$80e,$90b,$a0b,0
  400.  
  401.           dc.w    $80e,$90b,$a0b,0,$80e,$90b,$a0a,0
  402.           dc.w    $80e,$90b,$a0a,0,$80e,$90b,$a0a,0
  403.           dc.w    $80d,$90d,$a0b,0,$80d,$90d,$a0b,0
  404.           dc.w    $80d,$90d,$a0b,0,$80e,$90b,$a09,0
  405.           dc.w    $80e,$90b,$a09,0,$80e,$90b,$a09,0
  406.           dc.w    $80d,$90c,$a0c,0,$80d,$90d,$a0a,0
  407.           dc.w    $80e,$90b,$a07,0,$80e,$90b,$a00,0
  408.           dc.w    $80e,$90b,$a00,0,$80d,$90d,$a09,0
  409.  
  410.           dc.w    $80d,$90d,$a09,0,$80e,$90a,$a09,0
  411.           dc.w    $80d,$90d,$a08,0,$80d,$90d,$a07,0
  412.           dc.w    $80d,$90d,$a04,0,$80d,$90d,$a00,0
  413.           dc.w    $80e,$90a,$a04,0,$80e,$909,$a09,0
  414.           dc.w    $80e,$909,$a09,0,$80d,$90c,$a0b,0
  415.           dc.w    $80e,$909,$a08,0,$80e,$909,$a08,0
  416.           dc.w    $80e,$909,$a07,0,$80e,$908,$a08,0
  417.           dc.w    $80e,$909,$a01,0,$80c,$90c,$a0c,0
  418.  
  419.           dc.w    $80d,$90c,$a0a,0,$80e,$908,$a06,0
  420.           dc.w    $80e,$907,$a07,0,$80e,$908,$a00,0
  421.           dc.w    $80e,$907,$a05,0,$80e,$906,$a06,0
  422.           dc.w    $80d,$90c,$a09,0,$80e,$905,$a05,0
  423.           dc.w    $80e,$904,$a04,0,$80d,$90c,$a08,0
  424.           dc.w    $80d,$90b,$a0b,0,$80e,$900,$a00,0
  425.           dc.w    $80d,$90c,$a06,0,$80d,$90c,$a05,0
  426.           dc.w    $80d,$90c,$a02,0,$80c,$90c,$a0b,0
  427.  
  428.           dc.w    $80c,$90c,$a0b,0,$80d,$90b,$a0a,0
  429.           dc.w    $80d,$90b,$a0a,0,$80d,$90b,$a0a,0
  430.           dc.w    $80d,$90b,$a0a,0,$80c,$90c,$a0a,0
  431.           dc.w    $80c,$90c,$a0a,0,$80c,$90c,$a0a,0
  432.           dc.w    $80d,$90b,$a09,0,$80d,$90b,$a09,0
  433.           dc.w    $80d,$90a,$a0a,0,$80d,$90a,$a0a,0
  434.           dc.w    $80d,$90a,$a0a,0,$80c,$90c,$a09,0
  435.           dc.w    $80c,$90c,$a09,0,$80c,$90c,$a09,0
  436.  
  437.           dc.w    $80d,$90b,$a06,0,$80c,$90b,$a0b,0
  438.           dc.w    $80c,$90c,$a08,0,$80d,$90b,$a00,0
  439.           dc.w    $80d,$90b,$a00,0,$80c,$90c,$a07,0
  440.           dc.w    $80c,$90c,$a06,0,$80c,$90c,$a05,0
  441.           dc.w    $80c,$90c,$a03,0,$80c,$90c,$a01,0
  442.           dc.w    $80c,$90b,$a0a,0,$80d,$90a,$a05,0
  443.           dc.w    $80d,$90a,$a04,0,$80d,$90a,$a02,0
  444.           dc.w    $80d,$909,$a08,0,$80d,$909,$a08,0
  445.  
  446. snd_buf   ds.l 20000              ; reserve 80k bytes for sample data
  447.           end
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.